
#define Heater_Variable
#include "userDef.h"


void HeaterAct(void)
{
    if (ErrFlagQT == 0 && ErrFlag == 0 && CapTestStat == 0 && f_OutErr_Ub == 0 && f_ModeClash == 0)
    {
        if (b_power.run == ON && e_mode.run == MODEHEAT && f_RoomUnitOn == 1 && f_Defrosting == 0 && b_heater.set == ON)
        {
            if (f_Heater == 0)
            {
                if (HeaterOffSec >= 120 && HeaterOnTubeSec == 0 && speedNowValue1 > 100)
                {
                 /*
                    if (f_heaterFirstOn_End == ON || temp.outdoor <= (400 - 20))
                    {
                        f_heaterFirstOn_End = ON;

                        f_Heater = 1;
                        HeaterOffSec = 0;
                    }
				  */
					if(Heat.state == ForcedOpenAuxiliaryHeating) // 强制开启辅热
					{
                        f_Heater = 1;
                        HeaterOffSec = 0;
					}
					else if(OutdoorMachine.AD_OutEnvironment<AD_OutdoorMachine_OutEnvironment_0) //
					{
					   f_Heater = 1;
					   HeaterOffSec = 0;
					}
                }
            }
            else
            {
              /*
                if ((f_heaterFirstOff_End == OFF && temp.outdoor >= 400) || HeaterOffTubeSec == 0)
                {
                    f_heaterFirstOff_End = ON;

                    f_Heater = 0;
                }
                */
			       if(HeaterOffTubeSec == 0) // 强制开启辅热
					{
                      f_Heater = 0;
					}
					else if(OutdoorMachine.AD_OutEnvironment>AD_OutdoorMachine_OutEnvironment_1) //
					{
					   f_Heater = 0;
					}
			
            }
        }
        else
        {
            f_Heater = 0;
        }
    }
    else
    {
        f_Heater = 0;
    }
}

void HeaterLowTime(void)
{
    if (e_mode.run == MODEHEAT && f_RoomUnitOn == 1)
    {
        if (e_fanStep.run != FANSTOP && f_Heater == OFF)
        {
            if (HeaterOnTubeSec > 0)
            {
                if (e_fanStep.run >= FANLEVEL6)
                {
                    if (temp.tubeAct <= High_Speed_Close)
                    {
                        HeaterOnTubeSec--;
                    }
                    else
                    {
                        HeaterOnTubeSec = 30;
                    }
                }
                else if (e_fanStep.run >= FANLEVEL3)
                {
                    if (temp.tubeAct <= Mid_Speed_Close)
                    {
                        HeaterOnTubeSec--;
                    }
                    else
                    {
                        HeaterOnTubeSec = 30;
                    }
                }
                else
                {
                    if (temp.tubeAct <= Low_Speed_Close)
                    {
                        HeaterOnTubeSec--;
                    }
                    else
                    {
                        HeaterOnTubeSec = 30;
                    }
                }
            }
        }
        else
        {
            HeaterOnTubeSec = 30;
        }
    }
    else
    {
        HeaterOnTubeSec = 30;
    }

    if (f_Heater == ON)
    {
        if (HeaterOffTubeSec > 0)
        {
            if (e_fanStep.run >= FANLEVEL6)
            {
                if (temp.tubeAct >= High_Speed_Start)
                {
                    HeaterOffTubeSec--;
                }
                else
                {
                    HeaterOffTubeSec = 30;
                }
            }
            else if (e_fanStep.run >= FANLEVEL3)
            {
                if (temp.tubeAct >= Mid_Speed_Start)
                {
                    HeaterOffTubeSec--;
                }
                else
                {
                    HeaterOffTubeSec = 30;
                }
            }
            else
            {
                if (temp.tubeAct >= Low_Speed_Start)
                {
                    HeaterOffTubeSec--;
                }
                else
                {
                    HeaterOffTubeSec = 30;
                }
            }
        }
    }
    else
    {
        HeaterOffTubeSec = 30;
    }
}

void HeaterOffTime(void)
{
    if (f_Heater == 0)
    {
        if (HeaterOffSec < 250)
        {
            HeaterOffSec += Norm01Fast30;
        }
    }
    else
    {
        HeaterOffSec = 0;
    }
}

#ifdef HEATER_ERR
void HeaterErrCheck(void)
{
    if (f_Heater == 0 && IO_HEATERERR == 1)
    {
        if (HeaterErrSec < 30)
        {
            HeaterErrSec++;
        }
        else
        {
            f_HeaterErr = 1;
            f_Heater = 0;
        }
    }
    else
    {
        HeaterErrSec = 0;
    }

    if (f_HeaterErr == 1)
    {
        BuzzerAct(BUZZER100ms);
    }
}
#endif

